package com.atguigu.yygh.cmn.exceldemo;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author:ahang
 * @create:2022-08-31 0:10
 * @Description:
 */
@Component
public class ExcelReadListener extends AnalysisEventListener<DictEeVo> {

    @Autowired
    DictMapper dictMapper;


    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //逐行读取到excel中的每一条数据到dict表中
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}

